//
//  THJTAdePurchaseVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2017/11/7.
//  Copyright © 2017年 河南德艺. All rights reserved.
//  他的求购

#import "THJTAdePurchaseVC.h"
#import "THJTAdeFabuCell.h"
#import "ZBNetworking.h"
#import <MJRefresh.h>
@interface THJTAdePurchaseVC ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * _tableView;
    NSInteger pageNO;
}
@property (strong,nonatomic) NSMutableArray * listArr;
@end

@implementation THJTAdePurchaseVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStateBarColor:SingleColor(clearColor)];
}
-(NSMutableArray*)listArr{
    if(!_listArr){
        _listArr = [[NSMutableArray alloc] init];
    }
    return _listArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setHidden:YES];
    pageNO = 1;
    [self getDataWithPage:pageNO];
}
-(void)getDataWithPage:(NSInteger)page{
    NSLog(@"求购平台");
    [MBProgressHUD showMessage:@"" toView:self.view];
    __weak typeof(self) weakself = self;
    [ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
        request.urlString= [NSString stringWithFormat:@"%@index.php?f=buy_6&r=buy_6&userid=%@&page=%ld",THJUrlDomain,self.cid,page];
        NSLog(@"公司求购列表-url--%@",request.urlString);
        request.apiType=ZBRequestTypeCache;
    }  success:^(id responseObject,apiType type){
        NSDictionary * receiveData = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"qiugou-%@",receiveData);
        [MBProgressHUD hideHUDForView:weakself.view animated:YES];
        if([receiveData[@"status"] isEqual:@"200"]){
            NSDictionary * companInfoDic =receiveData[@"data"][@"member"];
            [weakself.logoImgV sd_setImageWithURL:[NSURL URLWithString:companInfoDic[@"logo"]] placeholderImage:kGetImage(@"占位图")];
            weakself.companyLab.text = companInfoDic[@"company"];
            weakself.addressLab.text = companInfoDic[@"address"];
            
            for (NSDictionary * dic in receiveData[@"data"][@"buy_list"]) {
                [weakself.listArr addObject:dic];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
              _tableView =   [weakself setTableviewWithFrame:CGRectMake(0, 140, ScreenWidth, ScreenHeight-140) RegisterNibNameArr:@[@"THJTAdeFabuCell"] ReuseIdentifierArr:@[@"cell"] RowHeight:145 BgColor:SingleColor(whiteColor) IsLoadMore:YES];
            });
        }
    } failed:^(NSError *error){
        
    }];
}
-(void)loadMore{
    pageNO++;
    [_tableView.mj_footer  endRefreshing];
    [self getDataWithPage:pageNO];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    THJTAdeFabuCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    NSDictionary * dic = self.listArr[indexPath.row];
    cell.titleLab.text = dic[@"title"];
    cell.addressLab.text = dic[@"address"];
    cell.dateLab.text = [self timeChangeWithString:dic[@"addtime"]];
    cell.companLab.text = dic[@"company"];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (IBAction)backBtnAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)menuBtnAction:(id)sender {
    NSLog(@"菜单点击");
}
- (IBAction)phoneBtnAction:(id)sender {
    NSLog(@"拨打电话");
    NSString * str=@"telprompt://400-900-6014";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
@end
